<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt />
      </div>
      <!-- <i class="pic" icon="el-icon-delete"></i> -->

      <div class="touxiang">
        <el-button type="info" @click="logout" class="btn">退出</el-button>

        <div class="myName">{{ this.userName }}</div>

        <el-button
          icon="el-icon-user-solid"
          circle
          ref="btn"
          class="pic"
        ></el-button>
      </div>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside>
        <!-- 侧边栏菜单区域 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <!-- <i :class="iconsObj[item.id]"></i> -->
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.path)"
            >
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{ subItem.name }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "obq",
  data() {
    return {
      userName: "",
      // 左侧菜单数据
      // 左侧菜单数据
      menulist: [
        {
          id: 1,
          authName: "医废数据管理",
          children: [{ id: 1, name: "医废数据表板", path: "home" }],
        },
        // {
        //   id: 2,
        //   authName: '用户管理',
        //
        // },
        {
          id: 2,
          authName: "医废管理",
          children: [
            { id: 1, name: "医废明细追踪", path: "detailed" },
            // { id: 2, name: '医废类别占比', path: 'proportion' },

            // { id: 2, name: '暂存点管理', path: 'scratch' },
            { id: 3, name: "科室管理", path: "department" },
            { id: 4, name: "转运公司管理", path: "transport" },
            { id: 5, name: "医废报表", path: "wasteReport" },
          ],
        },
        {
          id: 3,
          authName: "系统设置",
          children: [
            { id: 1, name: "用户管理", path: "administration" },
            { id: 2, name: "人员管理", path: "personnel" },
          ],
        },
      ],

      // 是否折叠
      isCollapse: false,
      // 被激活的链接地址
      activePath: "",
    };
  },

  mounted() {},
  created() {
    setTimeout(() => {
      // console.log(sessionStorage.valueOf())
      // console.log(123)
      // console.log(this.$route.query.name)
      // console.log(this.$store.state.userId)
      if ((this.userName = window.sessionStorage.getItem("userName") == null)) {
        this.userName = this.$store.state.MyUserName;
      } else {
        this.userName = window.sessionStorage.getItem("userName");
      }
      console.log(this.$store.state.MyUserName, 22);
      console.log(window.sessionStorage.getItem("userName"));
    }, 800);

    this.activePath = window.sessionStorage.getItem("activePath");
    if (window.sessionStorage.getItem("userId") != 2) {
      this.menulist[2].children = [];
    }
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      window.localStorage.clear();
      sessionStorage.removeItem("token");
      this.$router.push("/");
    },
    // 获取所有的菜单
    // async getMenuList() {
    //   const { data: res } = await this.$http.get('menus')
    //   if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
    //   this.menulist = res.data
    //   console.log(res)
    // },

    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
};
</script>

<style lang="less" scoped>
.el-main {
  // height: 1000px;
  padding: 0;
}
.home-container {
  height: 100%;
}
.el-header {
  height: 3.25rem !important;
  background-color: #373d41;
  display: flex;
  // justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 1.25rem;
  img {
    margin-left: 0rem;
    height: 3.25rem;
  }
}

.el-aside {
  width: 15rem !important;
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin-right: 0.625rem;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 0.625rem;
  line-height: 1.5rem;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
// .el-submenu {
//   font-size: 24px;
// }
// .myName {
//   width: 100%;
//   // margin-right: 20px;
//   height: 3.25rem;
//   line-height: 3.25rem;
//   padding-left: 1.125rem;
//   // padding-right: 10px;
// }
// .pic {
//   margin-left: 90rem;
//   cursor: none;
// }
// .btn {
//   margin-left: 0.625rem;
// }
.touxiang {
  height: 3.25rem !important;
  width: 100%;
  // float: right;
  // background-color: pink;
}
.pic {
  margin-top: 0.375rem;
  margin-right: 1.25rem;
  float: right;
}
.myName {
  margin-top: 0.75rem;
  margin-right: 1.25rem;
  float: right;
}
.btn {
  margin-top: 0.375rem;
  float: right;
}
// .touxiang {
//   width: auto;
//   display: inline-block;
//   position: relative;
//   .pic {
//     position: absolute;
//     top: -20px;
//     left: 93.75rem;
//     display: inline-block;
//   }
//   .myName {
//     position: absolute;
//     top: -12px;
//     left: 96.875rem;
//     display: inline-block;
//     margin-left: 0.9375rem;
//   }
//   .btn {
//     position: absolute;
//     top: -20px;
//     left: 105rem;
//   }
// }
</style>
